package com.example.prototype.person;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class PrototypePersonTest {


    public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException {
        Person person = new Person();
        person.setName("张三");
        List<String> list = new ArrayList<>();
        list.add("李四");
        person.setList(list);

        // 浅克隆 name 和 list 的内存地址一样
        Person clonePerson = person.clone();
        System.out.println(clonePerson.getName());

        // 深克隆 name 和 list 的内存地址不一样
        Person deepClonePerson = person.deepClone();
        System.out.println(deepClonePerson.getName());

        // 原型 和 深克隆 出来的对象内存地址不一样
        System.out.println(person.getName() == deepClonePerson.getName());



        String ab = "ab";
        System.out.println(Integer.toHexString(ab.hashCode()));
        String a = "a";
        String b = "b";
        String str = a + "b";
        System.out.println(Integer.toHexString(str.hashCode()));
        System.out.println(ab == str);

        person.setName("json");
        Person jsonClone = person.jsonClone();
        System.out.println("person:"+person.getList());
        System.out.println("jsonClone:"+jsonClone.getList());

    }


}
